import QtQuick 2.0
import QtQuick.Extras 1.4
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.3
import "storage.js" as Storage

Item {
    id: element
    width: 850
    height: 580

    signal qmlSN_sqlWriteFinish()
    onQmlSN_sqlWriteFinish: {
//        console.log("->page3 operater start")
        var t_var = Storage.readWhichChannelRunning()
        eXC_Gauge.circularGaugeValue = 0.01*$sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"机端电压")
        eXC_Gauge.circularGaugeValue = 0.01*$sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"励磁电流")
        if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","零起升压")===true)
            radioButton_alingqi.checked = true;
        else
            radioButton_alingqi.checked = false;

        if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","残压起励")===true)
            radioButton_acanya.checked = true;
        else
            radioButton_acanya.checked = false;
        if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","零起升压")===true)
            radioButton_blingqi.checked = true;
        else
            radioButton_blingqi.checked = false;
        if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","残压起励")===true)
            radioButton_bcanya.checked = true;
        else
            radioButton_bcanya.checked = false;
//        console.log("->page3 operater stop")
    }

    EXC_Gauge3 {
        id: eXC_Gauge
        width: parent.width/5
        anchors.left: parent.left
        anchors.leftMargin: parent.width/5
        element_cnmsgText: "定子电压 自动给定"
    }

    EXC_Gauge3 {
        id: eXC_Gauge2
        width: parent.width/5
        anchors.left: parent.left
        anchors.leftMargin: parent.width/5*3
        element_cnmsgText: "励磁电流 手动给定"
        element_numsizeText: "A"
        element_tipText: "If(%)"
    }

    Column {
        id: column
        width: parent.width*0.4
        height: parent.height*0.3
        anchors.left: parent.left
        anchors.leftMargin: parent.width/20
        anchors.topMargin: parent.height/20
        anchors.top: eXC_Gauge.bottom

        Text {
            text: qsTr("A通道起励方式")
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: parent.height*0.13
            fontSizeMode: Text.HorizontalFit
            height: parent.height*0.2
            color: "#40FFFF"
        }

        Row {
            id: row
            width: parent.width
            height: parent.height*0.4

            EXC_Normal_CheckBoxSytle {
                id: radioButton_alingqi
                text: qsTr("零起升压")
                width: parent.width*0.45
                anchors.verticalCenter: parent.verticalCenter
                textSize: 25*main_screen.minSize
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_lingin
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("投入")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A套零起投入\''))
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_lingout
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("退出")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A套零起退出\''))
                }
            }

        }

        Row {
            width: parent.width
            height: parent.height*0.4
            EXC_Normal_CheckBoxSytle {
                id: radioButton_acanya
                width: parent.width*0.45
                text: qsTr("残压起励")
                anchors.verticalCenter: parent.verticalCenter
                textSize: 25*main_screen.minSize
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_acanin
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("投入")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A残压起励投\''))
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_acanout
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("退出")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A残压起励退\''))
                }
            }
        }
    }

    Column {
        id: column1
        width: parent.width*0.4
        height: parent.height*0.3
        anchors.leftMargin: parent.width/10
        anchors.left: column.right
        anchors.topMargin: parent.height/20
        anchors.top: eXC_Gauge.bottom


        Text {
            text: qsTr("B通道起励方式")
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: parent.height*0.13
            fontSizeMode: Text.HorizontalFit
            height: parent.height*0.2
            color: "#40FFFF"
        }

        Row {
            width: parent.width
            height: parent.height*0.4

            EXC_Normal_CheckBoxSytle {
                id: radioButton_blingqi
                width: parent.width*0.45
                text: qsTr("零起升压")
                anchors.verticalCenter: parent.verticalCenter
                textSize: 25*main_screen.minSize
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_blingin
                height: parent.height*0.6
                width: parent.width*0.28
                nameText:  qsTr("投入")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套零起投入\''))
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_blingout
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("退出")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套零起退出\''))
                }
            }

        }

        Row {
            width: parent.width
            height: parent.height*0.4
            EXC_Normal_CheckBoxSytle {
                id: radioButton_bcanya
                text: qsTr("残压起励")
                width: parent.width*0.45
                anchors.verticalCenter: parent.verticalCenter
                textSize: 25*main_screen.minSize
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_bcanin
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("投入")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套残压起励投\''))
                }
            }

            EXC_Normal_BtnUncheckSecret_highStyle {
                id: button_bcanout
                height: parent.height*0.6
                width: parent.width*0.28
                nameText: qsTr("退出")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套残压起励退\''))
                }
            }
        }
    }

    EXC_Normal_BtnUncheckWindowStyle{
        id: button
        height: button_bcanout.height*1.7
        width: button_bcanout.width*2
        nameText: qsTr("起励")
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: column.bottom
        anchors.topMargin: parent.height/25
        onClicked: {
            if($sqlMcRecorder.qml_getBitBool("","通讯故障","1#调节器通讯故障")===false)
                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A套起励\''))
            if($sqlMcRecorder.qml_getBitBool("","通讯故障","2#调节器通讯故障")===false)
                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套起励\''))
        }
    }


}


